//
//  TitleView.m
//  cityStar
//
//  Created by joyban on 15-2-3.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "TitleView.h"

@implementation TitleView

@synthesize titleView,titleLabel,imageOne,imageTwo,arrayTitleList;

-(id)initWithFrame:(CGRect)frame setArray:(NSArray *)array
{
    self = [super initWithFrame:frame];
    if (self) {
        arrayTitleList = array;
        [self setDrawView];
    }
    return self;
}

-(void)setDrawView
{
    float sized = 10;
    float heght = 25;
    int m = 0;
    float frameWidth = self.frame.size.width;
    for (int i = 0; i<arrayTitleList.count; i++)
    {
        NSString *ss = [NSString stringWithFormat:@"%@",[arrayTitleList objectAtIndex:i]];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, frameWidth - 20, 25)];
        label.font = [UIFont systemFontOfSize:14];
        [label setLineBreakMode:NSLineBreakByWordWrapping];
        [label setNumberOfLines:0];
        NSString *_Detail = [NSString stringWithFormat:@"%@",ss];
        label.text = _Detail;
        [label sizeToFit];
        float width = label.frame.size.width;
        float thewidth = width + sized;
        if(thewidth > (frameWidth - 20))
        {
            sized = 10;
            m = m +1;
        }
        float titleheght = (heght+5) * m;
        titleView = [[UIView alloc]initWithFrame:CGRectMake(sized, 10+titleheght,width+20, heght)];
        sized = titleView.frame.size.width + sized+5;
        
        imageOne = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 5, heght)];
        imageOne.image = [UIImage imageNamed:@"tipone"];
        imageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(titleView.frame.size.width -15, 0, 15, heght)];
        imageTwo.image = [UIImage imageNamed:@"tiptwo"];
        titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, titleView.frame.size.width-20, heght)];
        titleLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tipthree"]];
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.text = ss;
        titleView.backgroundColor = [UIColor clearColor];
        [titleView addSubview:imageOne];
        [titleView addSubview:imageTwo];
        [titleView addSubview:titleLabel];
        [self addSubview:titleView];
    }

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
